home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / tool-inc.zip / FLAGS.INC < prev    next >
Text File  |  1989-06-02  |  1KB  |  46 lines

  1.  
  2. (*
  3.  * Copyright 1987, 1989 Samuel H. Smith;  All rights reserved
  4.  *
  5.  * This is a component of the ProDoor System.
  6.  * Do not distribute modified versions without my permission.
  7.  * Do not remove or alter this notice or any other copyright notice.
  8.  * If you use this in your own program you must distribute source code.
  9.  * Do not use any of this in a commercial product.
  10.  *
  11.  *)
  12.  
  13. (*
  14.  * flags.inc - Library to manipulate flag bits in a byte
  15.  *
  16.  *)
  17.  
  18. (* --------------------------------------------------------- *)
  19. function getflag(flag: byte; bitval: byte): boolean;
  20.    {return true/false for specified is set}
  21. begin
  22.    getflag := (flag and bitval) <> 0;
  23. end;
  24.  
  25. (* --------------------------------------------------------- *)
  26. procedure setflag(var flag: byte; bitval: byte; value: boolean);
  27.    {set the specified bit in a flagbyte}
  28. begin
  29.    if value then
  30.       flag := flag or bitval
  31.    else
  32.       flag := flag and (255 - bitval);
  33. end;
  34.  
  35. (* --------------------------------------------------------- *)
  36. function toggleflag(var flag: byte; bitval: byte): boolean;
  37.    {toggle the specified bit and return new setting}
  38. var
  39.    value:  boolean;
  40. begin
  41.    value := not getflag(flag,bitval);
  42.    setflag(flag,bitval,value);
  43.    toggleflag := value;
  44. end;
  45.  
  46.